<template>
  <div id="app">
    <transition :name="transitionName">
      <!-- <router-view/> -->
      <vue-page-transition>
        <router-view />
      </vue-page-transition>
    </transition>
  </div>
</template>

<script>
export default {
  name: "App",
  data() {
    return {
      transitionName: "",
    };
  },
  watch: {
    //使用watch 监听$router的变化
    $route(to, from) {
      //如果to索引大于from索引,判断为前进状态,反之则为后退状态
      console.log(to, "to");
      console.log(from, "from");
      if (to.meta.index > from.meta.index) {
        //设置动画名称
        this.transitionName = "slide-left";
      } else {
        this.transitionName = "slide-right";
      }
    },
  },
};
</script>

<style>
* {
  margin: 0;
  padding: 0;
  list-style: none;
  text-decoration: none;
}
html,
body,
.body-container {
  height: 100%;
  background: rgb(241, 241, 241);
}
#app {
  /* display: flex; */
  font-family: "Avenir", Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  /* text-align: center; */
  color: #2c3e50;
}
.title-box {
  width: 80%;
  height: 60px;
  background: white;
  /* border: 1px solid rgb(224, 142, 34); */
  box-shadow: 1px 1px 3px #2f6d9c3a;
  border-radius: 8px;
  font-size: 24px;
  line-height: 60px;
  margin-left: 100px;
  padding-left: 40px;
}
.box-raduis-8 {
  width: 80%;
  /* height: 60px; */
  /* border: 1px solid rgb(224, 142, 34); */
  border-radius: 8px;
  box-shadow: 1px 1px 3px #2f6d9c3a;
  background: white;
  font-size: 24px;
  line-height: 60px;
  margin: 20px 0px 0 100px;
  padding: 20px 0px 60px 40px;
}

.slide-right-enter-active,
.slide-right-leave-active,
.slide-left-enter-active,
.slide-left-leave-active {
  will-change: transform;
  transition: all 500ms;
  position: relative;
}

.slide-right-enter {
  opacity: 0;
  transform: translate(-100%, 0, 0);
}

.slide-right-leave-active {
  opacity: 0;
  transform: translate(100%, 0, 0);
}

.slide-left-enter {
  opacity: 0;
  transform: translate(100%, 0, 0);
}

.slide-left-leave-active {
  opacity: 0;
  transform: translate(-100%, 0, 0);
}
</style>
